package com.rich.dmr.handler;

import android.os.Handler;
import android.os.Message;
import java.util.ArrayList;
import java.util.List;

public class DmrHandler extends Handler {
    private static DmrHandler dmrHandler;
    private List<HandlerCallBack> handlerList = new ArrayList<>();
    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        for (HandlerCallBack handlerCallBack : handlerList) {
            handlerCallBack.updateFrequency(msg);
        }
    }
    private DmrHandler(){}
    public static DmrHandler getInstance(){
        if(dmrHandler == null){
            dmrHandler = new DmrHandler();
        }
        return dmrHandler;
    }

    public void setHandlerCallBack(HandlerCallBack handlerCallBack){
        handlerList.add(handlerCallBack);
    }

    public void removeHandlerCallBack(HandlerCallBack handlerCallBack){
        handlerList.remove(handlerCallBack);
    }

    public interface HandlerCallBack{
        void updateFrequency(Message msg);
    }
}
